import { savePdf } from "@/utils/savePdf";
import { addEvent } from "@/utils/index";
import type { DirectiveBinding } from "vue";
interface Options {
  title: string;
}

const vPdf = {
  directiveName: "pdf",
  // vue3 指定挂载
  mounted(el: HTMLElement, binding: DirectiveBinding<any>) {
    let exportElement: string;
    let options: Options = { title: "PDF" };
    addEvent(el, "click", () => {
      if (!binding.value) {
        return;
      }
      if (typeof binding.value === "object") {
        exportElement = binding.value.el;
        console.log(exportElement);
        options = binding.value;
        savePdf(exportElement, options.title);
      }
    });
  }
};

export default vPdf;
